package threadpool;

import thread.ThreadUtils;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadPoolSubmitCallableDemo {

    public static void main(String[] args) throws Exception {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 8; i++) {
            Future<String> callableString = threadPool.submit(new Callable<String>() {
                @Override
                public String call() {
                    ThreadUtils.sleep(1000);
                    return "当前线程：" + Thread.currentThread().getName();
                }
            });
            System.out.println("线程运行结果：" + callableString.get());
        }
        threadPool.shutdown();
    }
}
